---
slug: "api/search"
title: "Search"
---

Vrite provides a built-in, workspace-wide hybrid search powered by [Weaviate](https://weaviate.io/) and [OpenAI](https://openai.com/)’s API. Vrite chunks and index all content pieces following the headings (document structure) of each piece. The API allows you to both search and get answers to your questions via a question-answering endpoint based on GPT-4o.

## Search

Searches the content base using the provided query. Can search for content chunks in the specified variant, content group, or content piece.

Additionally, it provides an option to limit the search results and search the content pieces (rather than chunks) by their title.

<EndpointCard method="GET" endpoint="/search">
  <ResponseExample>
    ```json
    [
      {
        "contentPieceId": "string",
        "contentPiece": {
          "id": "bbe901d9e4a43a17cf660bb5",
          "date": "string",
          "title": "string",
          "description": "string",
          "tags": [
            "deeff099c94664f7f884e2a7"
          ],
          "coverUrl": "string",
          "coverAlt": "string",
          "contentGroupId": "13e4148f79235cea37a45553",
          "customData": "string",
          "canonicalLink": "string",
          "slug": "string",
          "filename": "string",
          "members": [
            "a9a55150f078ba1d1240cc45"
          ]
        },
        "breadcrumb": [
          "string"
        ],
        "content": "string"
      }
    ]
    ```
  </ResponseExample>
  
  <RequestExample label="JavaScript">
    ```javascript
    const client = createClient({
      token: "<API_TOKEN>"
    });
    const result = await client.search({
      query:"string",
      // Optional
      limit: 8,
      // Optional
      variantId: "a9a55150f078ba1d1240cc45",
      // Optional
      contentGroupId:"13e4148f79235cea37a45553",
      // Optional
      contentPieceId:"deeff099c94664f7f884e2a7",
      // Optional
      byTitle: false
    });
    ```
  </RequestExample>
</EndpointCard>

## Q&A Search

Uses Vrite search and GPT-4o with RAG to provide a simple question-answering experience for your Vrite workspace. It streams the answer via [SSEs](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events). Provides the same content filtering options as the `/search` endpoint.

<EndpointCard
  method="GET"
  endpoint="/search/ask"
  curl={false}
>
  <RequestExample label="JavaScript">
    ```javascript
    const client = createClient({
      token: "<API_TOKEN>",
    });
    const result = await client.ask({
      query: "string",
      // Optional
      variantId: "a9a55150f078ba1d1240cc45",
      // Optional
      contentGroupId: "13e4148f79235cea37a45553",
      // Optional
      contentPieceId: "deeff099c94664f7f884e2a7",
      // Callbacks
      onChunk(chunk, content) {
        console.log("Incoming chunk: ", chunk);
        console.log("Part of the answer that was already streamed: ", content);
      },
      onEnd(content) {
        console.log("Complete answer: ", content);
      },
      onError(error) {
        console.error(error);
      },
    });
    ```
  </RequestExample>
</EndpointCard>
